package kursynbp;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnectionFactory {

	String driverClassName = "org.postgresql.Driver";
	String connectionUrl = "jdbc:postgresql://localhost/kursynbp";
	String dbUser = "kursynbp";
	String dbPwd = "kursynbp";
	
	private static DBConnectionFactory connectionFactory = null;
	
	private DBConnectionFactory() {
	        try {
	                Class.forName(driverClassName);
	        } catch (ClassNotFoundException e) {
	                e.printStackTrace();
	        }
	}
	
	public Connection getConnection() throws SQLException {
	        Connection conn = null;
	        conn = DriverManager.getConnection(connectionUrl, dbUser, dbPwd);
	        return conn;
	}
	
	public static DBConnectionFactory getInstance() {
	        if (connectionFactory == null) {
	                connectionFactory = new DBConnectionFactory();
	        }
	        return connectionFactory;
	}
}
